<?php

namespace App\Admin\Forms;

use App\Models\User;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Contracts\LazyRenderable;

class Basketball extends Form implements LazyRenderable
{
    use LazyWidget;
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return Response
     */
    public function handle(array $input)
    {
        // dump($input);
        // 获取外部传递参数
        $user_id = $this->payload['id'] ?? null;
        $team_id = $input['team_id'] ?? null;
        //更新
        $res = User::where('id',$user_id)->update(['team_id'=>$team_id,'update_time' => time()]);
        if ($res){
            return $this->success('加入成功', '/User');
        }else{
            return $this->success('加入失败', '/User');
        }
    }
    /**
     * Build a form here.
     */
    public function form()
    {
        $this->select('team_id','球队')->options('team/teamData');
    }

}
